<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.6"/>
<title>Paho C++: src/mqtt/buffer_ref.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="pahologo.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">Paho C++
   &#160;<span id="projectnumber">1.0</span>
   </div>
   <div id="projectbrief">The Paho MQTT C++ Client Library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.6 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('buffer__ref_8h_source.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Friends</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">buffer_ref.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="buffer__ref_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;</div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment">/*******************************************************************************</span></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="comment"> * Copyright (c) 2017 Frank Pagliughi &lt;fpagliughi@mindspring.com&gt;</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="comment"> * All rights reserved. This program and the accompanying materials</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="comment"> * are made available under the terms of the Eclipse Public License v1.0</span></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="comment"> * and Eclipse Distribution License v1.0 which accompany this distribution.</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="comment"> * The Eclipse Public License is available at</span></div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="comment"> *    http://www.eclipse.org/legal/epl-v10.html</span></div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="comment"> * and the Eclipse Distribution License is available at</span></div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="comment"> *   http://www.eclipse.org/org/documents/edl-v10.php.</span></div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="comment"> * Contributors:</span></div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="comment"> *    Frank Pagliughi - initial implementation and documentation</span></div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="comment"> *******************************************************************************/</span></div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;</div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="preprocessor">#ifndef __mqtt_buffer_ref_h</span></div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="preprocessor"></span><span class="preprocessor">#define __mqtt_buffer_ref_h</span></div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="preprocessor"></span></div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="types_8h.html">mqtt/types.h</a>&quot;</span></div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;<span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;<span class="preprocessor">#include &lt;cstring&gt;</span></div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;<span class="keyword">namespace </span>mqtt {</div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;</div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a name="l00059"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html">   59</a></span>&#160;<span class="keyword">class </span><a class="code" href="classmqtt_1_1buffer__ref.html">buffer_ref</a></div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;{</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;<span class="keyword">public</span>:</div>
<div class="line"><a name="l00066"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#a1f962b2f5de758efac7e9f45b445d5a0">   66</a></span>&#160;    <span class="keyword">using</span> <a class="code" href="classmqtt_1_1buffer__ref.html#a1f962b2f5de758efac7e9f45b445d5a0">value_type</a> = T;</div>
<div class="line"><a name="l00071"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#a792a9ecfb61b558d575240a88b8195a0">   71</a></span>&#160;    <span class="keyword">using</span> <a class="code" href="classmqtt_1_1buffer__ref.html#a792a9ecfb61b558d575240a88b8195a0">blob</a> = std::basic_string&lt;value_type&gt;;</div>
<div class="line"><a name="l00076"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#a9bc5bece985507f5ac0979c9984b5105">   76</a></span>&#160;    <span class="keyword">using</span> <a class="code" href="classmqtt_1_1buffer__ref.html#a9bc5bece985507f5ac0979c9984b5105">pointer_type</a> = std::shared_ptr&lt;const blob&gt;;</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;</div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;<span class="keyword">private</span>:</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;    <a class="code" href="classmqtt_1_1buffer__ref.html#a9bc5bece985507f5ac0979c9984b5105">pointer_type</a> data_;</div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;</div>
<div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;<span class="keyword">public</span>:</div>
<div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;    <a class="code" href="classmqtt_1_1buffer__ref.html#a35212893609858049401f945acc2fc2e">buffer_ref</a>() =<span class="keywordflow">default</span>;</div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;    <a class="code" href="classmqtt_1_1buffer__ref.html#a35212893609858049401f945acc2fc2e">buffer_ref</a>(<span class="keyword">const</span> <a class="code" href="classmqtt_1_1buffer__ref.html">buffer_ref</a>&amp; buf) =<span class="keywordflow">default</span>;</div>
<div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;    <a class="code" href="classmqtt_1_1buffer__ref.html#a35212893609858049401f945acc2fc2e">buffer_ref</a>(<a class="code" href="classmqtt_1_1buffer__ref.html">buffer_ref</a>&amp;&amp; buf) =<span class="keywordflow">default</span>;</div>
<div class="line"><a name="l00101"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#ab0bb54e77affc6d6c5c8f27210e5bdec">  101</a></span>&#160;    <a class="code" href="classmqtt_1_1buffer__ref.html#ab0bb54e77affc6d6c5c8f27210e5bdec">buffer_ref</a>(<span class="keyword">const</span> <a class="code" href="classmqtt_1_1buffer__ref.html#a792a9ecfb61b558d575240a88b8195a0">blob</a>&amp; b) : data_{std::make_shared&lt;blob&gt;(b)} {}</div>
<div class="line"><a name="l00107"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#aff85012382a93bc6294be98c9a0a903d">  107</a></span>&#160;    <a class="code" href="classmqtt_1_1buffer__ref.html#aff85012382a93bc6294be98c9a0a903d">buffer_ref</a>(<a class="code" href="classmqtt_1_1buffer__ref.html#a792a9ecfb61b558d575240a88b8195a0">blob</a>&amp;&amp; b) : data_{std::make_shared&lt;blob&gt;(std::move(b))} {}</div>
<div class="line"><a name="l00115"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#adf4aff851797ef244a7483c16a27ca76">  115</a></span>&#160;    <a class="code" href="classmqtt_1_1buffer__ref.html#adf4aff851797ef244a7483c16a27ca76">buffer_ref</a>(<span class="keyword">const</span> <a class="code" href="classmqtt_1_1buffer__ref.html#a9bc5bece985507f5ac0979c9984b5105">pointer_type</a>&amp; p) : data_(p) {}</div>
<div class="line"><a name="l00123"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#a176e51bbc0062a284433af23c41b34c0">  123</a></span>&#160;    <a class="code" href="classmqtt_1_1buffer__ref.html#a176e51bbc0062a284433af23c41b34c0">buffer_ref</a>(<a class="code" href="classmqtt_1_1buffer__ref.html#a9bc5bece985507f5ac0979c9984b5105">pointer_type</a>&amp;&amp; p) : data_(std::move(p)) {}</div>
<div class="line"><a name="l00129"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#ac4aa4005b807f820eed02cf50dea273b">  129</a></span>&#160;    <a class="code" href="classmqtt_1_1buffer__ref.html#ac4aa4005b807f820eed02cf50dea273b">buffer_ref</a>(<span class="keyword">const</span> <a class="code" href="classmqtt_1_1buffer__ref.html#a1f962b2f5de758efac7e9f45b445d5a0">value_type</a>* buf, <span class="keywordtype">size_t</span> n) : data_{std::make_shared&lt;blob&gt;(buf,n)} {}</div>
<div class="line"><a name="l00135"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#a0595b66a3fb58e5a024345289ea7e855">  135</a></span>&#160;    <a class="code" href="classmqtt_1_1buffer__ref.html#a0595b66a3fb58e5a024345289ea7e855">buffer_ref</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* buf) : <a class="code" href="classmqtt_1_1buffer__ref.html">buffer_ref</a>(reinterpret_cast&lt;const <a class="code" href="classmqtt_1_1buffer__ref.html#a1f962b2f5de758efac7e9f45b445d5a0">value_type</a>*&gt;(buf), </div>
<div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;                                             std::strlen(buf)) {</div>
<div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;        static_assert(<span class="keyword">sizeof</span>(<span class="keywordtype">char</span>) == <span class="keyword">sizeof</span>(T), <span class="stringliteral">&quot;can only use C arr with char or byte buffers&quot;</span>);</div>
<div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;    }</div>
<div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;</div>
<div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;    <a class="code" href="classmqtt_1_1buffer__ref.html">buffer_ref</a>&amp; <a class="code" href="classmqtt_1_1buffer__ref.html#a8bae1b1db07ca36264ba6d48a99cdbe7">operator=</a>(<span class="keyword">const</span> <a class="code" href="classmqtt_1_1buffer__ref.html">buffer_ref</a>&amp; rhs) =<span class="keywordflow">default</span>;</div>
<div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;    <a class="code" href="classmqtt_1_1buffer__ref.html">buffer_ref</a>&amp; <a class="code" href="classmqtt_1_1buffer__ref.html#a8bae1b1db07ca36264ba6d48a99cdbe7">operator=</a>(<a class="code" href="classmqtt_1_1buffer__ref.html">buffer_ref</a>&amp;&amp; rhs) =<span class="keywordflow">default</span>;</div>
<div class="line"><a name="l00160"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#a47b2bd295fed12a14325a07b872a6dbd">  160</a></span>&#160;    <a class="code" href="classmqtt_1_1buffer__ref.html">buffer_ref</a>&amp; <a class="code" href="classmqtt_1_1buffer__ref.html#a47b2bd295fed12a14325a07b872a6dbd">operator=</a>(<span class="keyword">const</span> <a class="code" href="classmqtt_1_1buffer__ref.html#a792a9ecfb61b558d575240a88b8195a0">blob</a>&amp; b) {</div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;        data_.reset(<span class="keyword">new</span> <a class="code" href="classmqtt_1_1buffer__ref.html#a792a9ecfb61b558d575240a88b8195a0">blob</a>(b));</div>
<div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;        <span class="keywordflow">return</span> *<span class="keyword">this</span>;</div>
<div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;    }</div>
<div class="line"><a name="l00172"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#a929d718638a0646e6f484d07f1610faa">  172</a></span>&#160;    <a class="code" href="classmqtt_1_1buffer__ref.html">buffer_ref</a>&amp; <a class="code" href="classmqtt_1_1buffer__ref.html#a929d718638a0646e6f484d07f1610faa">operator=</a>(<a class="code" href="classmqtt_1_1buffer__ref.html#a792a9ecfb61b558d575240a88b8195a0">blob</a>&amp;&amp; b) {</div>
<div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160;        data_.reset(<span class="keyword">new</span> <a class="code" href="classmqtt_1_1buffer__ref.html#a792a9ecfb61b558d575240a88b8195a0">blob</a>(std::move(b)));</div>
<div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160;        <span class="keywordflow">return</span> *<span class="keyword">this</span>;</div>
<div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;    }</div>
<div class="line"><a name="l00181"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#ab9e1fcda1683788fba1eed65006ff375">  181</a></span>&#160;    <a class="code" href="classmqtt_1_1buffer__ref.html">buffer_ref</a>&amp; <a class="code" href="classmqtt_1_1buffer__ref.html#ab9e1fcda1683788fba1eed65006ff375">operator=</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* cstr) {</div>
<div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;        static_assert(<span class="keyword">sizeof</span>(<span class="keywordtype">char</span>) == <span class="keyword">sizeof</span>(T), <span class="stringliteral">&quot;can only use C arr with char or byte buffers&quot;</span>);</div>
<div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;        data_.reset(<span class="keyword">new</span> <a class="code" href="classmqtt_1_1buffer__ref.html#a792a9ecfb61b558d575240a88b8195a0">blob</a>(reinterpret_cast&lt;const value_type*&gt;(cstr), strlen(cstr)));</div>
<div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;        <span class="keywordflow">return</span> *<span class="keyword">this</span>;</div>
<div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;    }</div>
<div class="line"><a name="l00195"></a><span class="lineno">  195</span>&#160;    <span class="keyword">template</span> &lt;<span class="keyword">typename</span> OT&gt;</div>
<div class="line"><a name="l00196"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#ad9538182730ddbeb04ac35b8cbb95307">  196</a></span>&#160;    <a class="code" href="classmqtt_1_1buffer__ref.html">buffer_ref</a>&amp; <a class="code" href="classmqtt_1_1buffer__ref.html#ad9538182730ddbeb04ac35b8cbb95307">operator=</a>(<span class="keyword">const</span> <a class="code" href="classmqtt_1_1buffer__ref.html">buffer_ref&lt;OT&gt;</a>&amp; rhs) {</div>
<div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160;        static_assert(<span class="keyword">sizeof</span>(OT) == <span class="keyword">sizeof</span>(T), <span class="stringliteral">&quot;Can only assign buffers if values the same size&quot;</span>);</div>
<div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;        data_.reset(<span class="keyword">new</span> <a class="code" href="classmqtt_1_1buffer__ref.html#a792a9ecfb61b558d575240a88b8195a0">blob</a>(reinterpret_cast&lt;const value_type*&gt;(rhs.<a class="code" href="classmqtt_1_1buffer__ref.html#ac1b6fab48232abddbf8d1857e2bf751f">data</a>()), rhs.<a class="code" href="classmqtt_1_1buffer__ref.html#a9f0d34a9a04996bbf40274af07ac20d7">size</a>()));</div>
<div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160;        <span class="keywordflow">return</span> *<span class="keyword">this</span>;</div>
<div class="line"><a name="l00200"></a><span class="lineno">  200</span>&#160;    }</div>
<div class="line"><a name="l00204"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#adb825ca3db27ec312a4aeba1724f2c07">  204</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="classmqtt_1_1buffer__ref.html#adb825ca3db27ec312a4aeba1724f2c07">reset</a>() { data_.reset(); }</div>
<div class="line"><a name="l00212"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#acacac9264e401714ac4e0ffc58755bb6">  212</a></span>&#160;    <span class="keyword">explicit</span> <span class="keyword">operator</span> bool()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> bool(data_); }</div>
<div class="line"><a name="l00220"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#a6ce9a7a7cd68a6b3bd6f5b1bfc08e9cc">  220</a></span>&#160;    <span class="keywordtype">bool</span> <a class="code" href="classmqtt_1_1buffer__ref.html#a6ce9a7a7cd68a6b3bd6f5b1bfc08e9cc">is_null</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> !data_; }</div>
<div class="line"><a name="l00226"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#a7fc93b3215ffcb9f8798b6350ac0604f">  226</a></span>&#160;    <span class="keywordtype">bool</span> <a class="code" href="classmqtt_1_1buffer__ref.html#a7fc93b3215ffcb9f8798b6350ac0604f">empty</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> !data_ || data_-&gt;empty(); }</div>
<div class="line"><a name="l00231"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#ac1b6fab48232abddbf8d1857e2bf751f">  231</a></span>&#160;    <span class="keyword">const</span> <a class="code" href="classmqtt_1_1buffer__ref.html#a1f962b2f5de758efac7e9f45b445d5a0">value_type</a>* <a class="code" href="classmqtt_1_1buffer__ref.html#ac1b6fab48232abddbf8d1857e2bf751f">data</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> data_-&gt;data(); }</div>
<div class="line"><a name="l00236"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#a9f0d34a9a04996bbf40274af07ac20d7">  236</a></span>&#160;    <span class="keywordtype">size_t</span> <a class="code" href="classmqtt_1_1buffer__ref.html#a9f0d34a9a04996bbf40274af07ac20d7">size</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> data_-&gt;size(); }</div>
<div class="line"><a name="l00241"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#a5eb836c895c0a9978f544b9c497db96a">  241</a></span>&#160;    <span class="keywordtype">size_t</span> <a class="code" href="classmqtt_1_1buffer__ref.html#a5eb836c895c0a9978f544b9c497db96a">length</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> data_-&gt;length(); }</div>
<div class="line"><a name="l00246"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#ad43932e2a6a5debe8036d6d5af2d76da">  246</a></span>&#160;    <span class="keyword">const</span> <a class="code" href="classmqtt_1_1buffer__ref.html#a792a9ecfb61b558d575240a88b8195a0">blob</a>&amp; <a class="code" href="classmqtt_1_1buffer__ref.html#ad43932e2a6a5debe8036d6d5af2d76da">str</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> *data_; }</div>
<div class="line"><a name="l00251"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#a940a8cf306fd985b2f3c85a79328b423">  251</a></span>&#160;    <span class="keyword">const</span> <a class="code" href="classmqtt_1_1buffer__ref.html#a792a9ecfb61b558d575240a88b8195a0">blob</a>&amp; <a class="code" href="classmqtt_1_1buffer__ref.html#a940a8cf306fd985b2f3c85a79328b423">to_string</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classmqtt_1_1buffer__ref.html#ad43932e2a6a5debe8036d6d5af2d76da">str</a>(); }</div>
<div class="line"><a name="l00257"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#a686a9aecf29f8290e1ba8161ac81d12b">  257</a></span>&#160;    <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="classmqtt_1_1buffer__ref.html#a686a9aecf29f8290e1ba8161ac81d12b">c_str</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> data_-&gt;c_str(); }</div>
<div class="line"><a name="l00262"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#ade1b93fa4991a93f9151dcc758404721">  262</a></span>&#160;    <span class="keyword">const</span> <a class="code" href="classmqtt_1_1buffer__ref.html#a9bc5bece985507f5ac0979c9984b5105">pointer_type</a>&amp; <a class="code" href="classmqtt_1_1buffer__ref.html#ade1b93fa4991a93f9151dcc758404721">ptr</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> data_; }</div>
<div class="line"><a name="l00268"></a><span class="lineno"><a class="line" href="classmqtt_1_1buffer__ref.html#aaab117442ba1e5cf8d870bda1d0096f0">  268</a></span>&#160;    <span class="keyword">const</span> <a class="code" href="classmqtt_1_1buffer__ref.html#a1f962b2f5de758efac7e9f45b445d5a0">value_type</a>&amp; <a class="code" href="classmqtt_1_1buffer__ref.html#aaab117442ba1e5cf8d870bda1d0096f0">operator[]</a>(<span class="keywordtype">size_t</span> i)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> (*data_)[i]; }</div>
<div class="line"><a name="l00269"></a><span class="lineno">  269</span>&#160;};</div>
<div class="line"><a name="l00270"></a><span class="lineno">  270</span>&#160;</div>
<div class="line"><a name="l00278"></a><span class="lineno">  278</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a name="l00279"></a><span class="lineno">  279</span>&#160;std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const buffer_ref&lt;T&gt;&amp; buf) {</div>
<div class="line"><a name="l00280"></a><span class="lineno">  280</span>&#160;    <span class="keywordflow">if</span> (!buf.empty())</div>
<div class="line"><a name="l00281"></a><span class="lineno">  281</span>&#160;        os.write(buf.data(), buf.size());</div>
<div class="line"><a name="l00282"></a><span class="lineno">  282</span>&#160;    <span class="keywordflow">return</span> os;</div>
<div class="line"><a name="l00283"></a><span class="lineno">  283</span>&#160;}</div>
<div class="line"><a name="l00284"></a><span class="lineno">  284</span>&#160;</div>
<div class="line"><a name="l00286"></a><span class="lineno">  286</span>&#160;</div>
<div class="line"><a name="l00290"></a><span class="lineno">  290</span>&#160;<span class="keyword">using</span> string_ref = buffer_ref&lt;char&gt;;</div>
<div class="line"><a name="l00291"></a><span class="lineno">  291</span>&#160;</div>
<div class="line"><a name="l00298"></a><span class="lineno">  298</span>&#160;<span class="keyword">using</span> binary_ref = buffer_ref&lt;char&gt;;</div>
<div class="line"><a name="l00299"></a><span class="lineno">  299</span>&#160;</div>
<div class="line"><a name="l00301"></a><span class="lineno">  301</span>&#160;<span class="comment">// end namespace mqtt</span></div>
<div class="line"><a name="l00302"></a><span class="lineno">  302</span>&#160;}</div>
<div class="line"><a name="l00303"></a><span class="lineno">  303</span>&#160;</div>
<div class="line"><a name="l00304"></a><span class="lineno">  304</span>&#160;<span class="preprocessor">#endif      // __mqtt_buffer_ref_h</span></div>
<div class="line"><a name="l00305"></a><span class="lineno">  305</span>&#160;<span class="preprocessor"></span></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_a9f0d34a9a04996bbf40274af07ac20d7"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#a9f0d34a9a04996bbf40274af07ac20d7">mqtt::buffer_ref::size</a></div><div class="ttdeci">size_t size() const </div><div class="ttdoc">Gets the size of the data buffer. </div><div class="ttdef"><b>Definition:</b> buffer_ref.h:236</div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_a176e51bbc0062a284433af23c41b34c0"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#a176e51bbc0062a284433af23c41b34c0">mqtt::buffer_ref::buffer_ref</a></div><div class="ttdeci">buffer_ref(pointer_type &amp;&amp;p)</div><div class="ttdoc">Creates a reference to an existing buffer by moving the shared pointer. </div><div class="ttdef"><b>Definition:</b> buffer_ref.h:123</div></div>
<div class="ttc" id="types_8h_html"><div class="ttname"><a href="types_8h.html">types.h</a></div><div class="ttdoc">Basic types and type conversions for the Paho MQTT C++ library. </div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_a8bae1b1db07ca36264ba6d48a99cdbe7"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#a8bae1b1db07ca36264ba6d48a99cdbe7">mqtt::buffer_ref::operator=</a></div><div class="ttdeci">buffer_ref &amp; operator=(const buffer_ref &amp;rhs)=default</div><div class="ttdoc">Copy the reference to the buffer. </div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_a686a9aecf29f8290e1ba8161ac81d12b"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#a686a9aecf29f8290e1ba8161ac81d12b">mqtt::buffer_ref::c_str</a></div><div class="ttdeci">const char * c_str() const </div><div class="ttdoc">Gets the data buffer as NUL-terminated C string. </div><div class="ttdef"><b>Definition:</b> buffer_ref.h:257</div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_ad43932e2a6a5debe8036d6d5af2d76da"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#ad43932e2a6a5debe8036d6d5af2d76da">mqtt::buffer_ref::str</a></div><div class="ttdeci">const blob &amp; str() const </div><div class="ttdoc">Gets the data buffer as a string. </div><div class="ttdef"><b>Definition:</b> buffer_ref.h:246</div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_aff85012382a93bc6294be98c9a0a903d"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#aff85012382a93bc6294be98c9a0a903d">mqtt::buffer_ref::buffer_ref</a></div><div class="ttdeci">buffer_ref(blob &amp;&amp;b)</div><div class="ttdoc">Creates a reference to a new buffer by moving a string into the buffer. </div><div class="ttdef"><b>Definition:</b> buffer_ref.h:107</div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html">mqtt::buffer_ref</a></div><div class="ttdoc">A reference object for holding immutable data buffers, with cheap copy semantics and lifetime managem...</div><div class="ttdef"><b>Definition:</b> buffer_ref.h:59</div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_a1f962b2f5de758efac7e9f45b445d5a0"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#a1f962b2f5de758efac7e9f45b445d5a0">mqtt::buffer_ref&lt; char &gt;::value_type</a></div><div class="ttdeci">char value_type</div><div class="ttdoc">The underlying type for the buffer. </div><div class="ttdef"><b>Definition:</b> buffer_ref.h:66</div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_a792a9ecfb61b558d575240a88b8195a0"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#a792a9ecfb61b558d575240a88b8195a0">mqtt::buffer_ref&lt; char &gt;::blob</a></div><div class="ttdeci">std::basic_string&lt; value_type &gt; blob</div><div class="ttdoc">The type for the buffer. </div><div class="ttdef"><b>Definition:</b> buffer_ref.h:71</div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_a35212893609858049401f945acc2fc2e"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#a35212893609858049401f945acc2fc2e">mqtt::buffer_ref::buffer_ref</a></div><div class="ttdeci">buffer_ref()=default</div><div class="ttdoc">Default constructor creates a null reference. </div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_a5eb836c895c0a9978f544b9c497db96a"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#a5eb836c895c0a9978f544b9c497db96a">mqtt::buffer_ref::length</a></div><div class="ttdeci">size_t length() const </div><div class="ttdoc">Gets the size of the data buffer. </div><div class="ttdef"><b>Definition:</b> buffer_ref.h:241</div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_a929d718638a0646e6f484d07f1610faa"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#a929d718638a0646e6f484d07f1610faa">mqtt::buffer_ref::operator=</a></div><div class="ttdeci">buffer_ref &amp; operator=(blob &amp;&amp;b)</div><div class="ttdoc">Move a string into this object, creating a new buffer. </div><div class="ttdef"><b>Definition:</b> buffer_ref.h:172</div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_a47b2bd295fed12a14325a07b872a6dbd"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#a47b2bd295fed12a14325a07b872a6dbd">mqtt::buffer_ref::operator=</a></div><div class="ttdeci">buffer_ref &amp; operator=(const blob &amp;b)</div><div class="ttdoc">Copy a string into this object, creating a new buffer. </div><div class="ttdef"><b>Definition:</b> buffer_ref.h:160</div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_aaab117442ba1e5cf8d870bda1d0096f0"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#aaab117442ba1e5cf8d870bda1d0096f0">mqtt::buffer_ref::operator[]</a></div><div class="ttdeci">const value_type &amp; operator[](size_t i) const </div><div class="ttdoc">Gets elemental access to the data buffer (read only) </div><div class="ttdef"><b>Definition:</b> buffer_ref.h:268</div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_ab0bb54e77affc6d6c5c8f27210e5bdec"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#ab0bb54e77affc6d6c5c8f27210e5bdec">mqtt::buffer_ref::buffer_ref</a></div><div class="ttdeci">buffer_ref(const blob &amp;b)</div><div class="ttdoc">Creates a reference to a new buffer by copying data. </div><div class="ttdef"><b>Definition:</b> buffer_ref.h:101</div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_a6ce9a7a7cd68a6b3bd6f5b1bfc08e9cc"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#a6ce9a7a7cd68a6b3bd6f5b1bfc08e9cc">mqtt::buffer_ref::is_null</a></div><div class="ttdeci">bool is_null() const </div><div class="ttdoc">Determines if the reference is invalid. </div><div class="ttdef"><b>Definition:</b> buffer_ref.h:220</div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_ac4aa4005b807f820eed02cf50dea273b"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#ac4aa4005b807f820eed02cf50dea273b">mqtt::buffer_ref::buffer_ref</a></div><div class="ttdeci">buffer_ref(const value_type *buf, size_t n)</div><div class="ttdoc">Creates a reference to a new buffer containing a copy of the data. </div><div class="ttdef"><b>Definition:</b> buffer_ref.h:129</div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_a9bc5bece985507f5ac0979c9984b5105"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#a9bc5bece985507f5ac0979c9984b5105">mqtt::buffer_ref&lt; char &gt;::pointer_type</a></div><div class="ttdeci">std::shared_ptr&lt; const blob &gt; pointer_type</div><div class="ttdoc">The pointer we use. </div><div class="ttdef"><b>Definition:</b> buffer_ref.h:76</div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_a7fc93b3215ffcb9f8798b6350ac0604f"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#a7fc93b3215ffcb9f8798b6350ac0604f">mqtt::buffer_ref::empty</a></div><div class="ttdeci">bool empty() const </div><div class="ttdoc">Determines if the buffer is empty. </div><div class="ttdef"><b>Definition:</b> buffer_ref.h:226</div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_a0595b66a3fb58e5a024345289ea7e855"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#a0595b66a3fb58e5a024345289ea7e855">mqtt::buffer_ref::buffer_ref</a></div><div class="ttdeci">buffer_ref(const char *buf)</div><div class="ttdoc">Creates a reference to a new buffer containing a copy of the NUL-terminated char array. </div><div class="ttdef"><b>Definition:</b> buffer_ref.h:135</div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_ade1b93fa4991a93f9151dcc758404721"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#ade1b93fa4991a93f9151dcc758404721">mqtt::buffer_ref::ptr</a></div><div class="ttdeci">const pointer_type &amp; ptr() const </div><div class="ttdoc">Gets a shared pointer to the (const) data buffer. </div><div class="ttdef"><b>Definition:</b> buffer_ref.h:262</div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_ac1b6fab48232abddbf8d1857e2bf751f"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#ac1b6fab48232abddbf8d1857e2bf751f">mqtt::buffer_ref::data</a></div><div class="ttdeci">const value_type * data() const </div><div class="ttdoc">Gets a const pointer to the data buffer. </div><div class="ttdef"><b>Definition:</b> buffer_ref.h:231</div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_ab9e1fcda1683788fba1eed65006ff375"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#ab9e1fcda1683788fba1eed65006ff375">mqtt::buffer_ref::operator=</a></div><div class="ttdeci">buffer_ref &amp; operator=(const char *cstr)</div><div class="ttdoc">Copy a NUL-terminated C char array into a new buffer. </div><div class="ttdef"><b>Definition:</b> buffer_ref.h:181</div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_adb825ca3db27ec312a4aeba1724f2c07"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#adb825ca3db27ec312a4aeba1724f2c07">mqtt::buffer_ref::reset</a></div><div class="ttdeci">void reset()</div><div class="ttdoc">Clears the reference to nil. </div><div class="ttdef"><b>Definition:</b> buffer_ref.h:204</div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_adf4aff851797ef244a7483c16a27ca76"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#adf4aff851797ef244a7483c16a27ca76">mqtt::buffer_ref::buffer_ref</a></div><div class="ttdeci">buffer_ref(const pointer_type &amp;p)</div><div class="ttdoc">Creates a reference to an existing buffer by copying the shared pointer. </div><div class="ttdef"><b>Definition:</b> buffer_ref.h:115</div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_ad9538182730ddbeb04ac35b8cbb95307"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#ad9538182730ddbeb04ac35b8cbb95307">mqtt::buffer_ref::operator=</a></div><div class="ttdeci">buffer_ref &amp; operator=(const buffer_ref&lt; OT &gt; &amp;rhs)</div><div class="ttdoc">Copy another type of buffer reference to this one. </div><div class="ttdef"><b>Definition:</b> buffer_ref.h:196</div></div>
<div class="ttc" id="classmqtt_1_1buffer__ref_html_a940a8cf306fd985b2f3c85a79328b423"><div class="ttname"><a href="classmqtt_1_1buffer__ref.html#a940a8cf306fd985b2f3c85a79328b423">mqtt::buffer_ref::to_string</a></div><div class="ttdeci">const blob &amp; to_string() const </div><div class="ttdoc">Gets the data buffer as a string. </div><div class="ttdef"><b>Definition:</b> buffer_ref.h:251</div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="dir_503ebd9f384f44c9859dcb1451d026bc.html">mqtt</a></li><li class="navelem"><a class="el" href="buffer__ref_8h.html">buffer_ref.h</a></li>
    <li class="footer">Generated on Sun Jul 23 2017 10:24:29 for Paho C++ by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.6 </li>
  </ul>
</div>
</body>
</html>
